import requests
import bs4

def get_html(url):

    #The request
    headers= {
        'User-Agent':
        'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/51.0.2704.103 Safari/537.36',
        'ContentType':'text/html; charset=utf-8',
        'Accept-Encoding':'gzip,defalt,sdch',
        'Accept-Language':'zh-CN,zh;q=0.8',
        'Connection':'keep-alive',
    }

    try:
        htmlcontet =requests.get(url,headers=headers,timeout=30)
        htmlcontet.raise_for_status()
        htmlcontet.encoding='utf-8'
        return htmlcontet.text
    except:
        return "Request error"


def get_content(url):

    #get the data from the website

    weather_list=[]

    
    html=get_html(url)
    soup=bs4.BeautifulSoup(html,'lxml')
    content_ul=soup.find('div',class_='t').find('ul',class_='clearfix').find_all('li')
    for content in content_ul:
        try:
            weather={}
            weather['day']=content.find('h1').text
            weather['temperature']=content.find('p',class_='tem').span.text+content.find('p',class_='tem').em.text
            
            weather_list.append(weather)
        
        except:
            continue

    
    
    print(weather_list)

if __name__=='__main__':
    url='http://www.weather.com.cn/weather1d/101160101.shtml'
    get_content(url)


